SELECT <欄位名稱1> , <欄位名稱2>, ……
FROM <資料表名稱>
ORDER BY <排序基準欄位1> , <排序基準欄位2>……
SELECT food_id , food_name , food_catalg , sell_price , buy_price , profit
FROM food
ORDER BY profit
SELECT food_id , food_name , food_catalg , sell_price , buy_price , profit
FROM food
ORDER BY profit DESC;
以Ex1為例,有2筆紀錄profit皆為10,有4筆紀錄profit皆為15,我希望在profit相同時再按照buy_price做升冪
SELECT food_id , food_name , food_catalg , sell_price , buy_price , profit
FROM food
ORDER BY profit , buy_price;
原Ex1
修改後的Ex1
含有Null的排序鍵會被放在最前面或最後面的位置
SELECT food_id , food_name , food_catalg , sell_price , buy_price , profit
FROM food
ORDER BY sell_price;